package com.yuantu.judiciary.controller;

import com.yuantu.judiciary.common.Response;
import com.yuantu.judiciary.common.ResponseFactory;
import com.yuantu.judiciary.model.api.*;
import com.yuantu.judiciary.model.dto.AccountInfoDTO;
import com.yuantu.judiciary.model.dto.CaseSimpleDTO;
import com.yuantu.judiciary.model.dto.MonitorCaseDTO;
import com.yuantu.judiciary.model.vo.MonitorFileAddVO;
import com.yuantu.judiciary.model.vo.MonitorRecordAddVO;
import com.yuantu.judiciary.model.vo.MonitorRecordQueryVO;
import com.yuantu.judiciary.model.vo.MonitorRecordVO;
import com.yuantu.judiciary.service.IMonitorService;
import com.yuantu.judiciary.service.IOpenApiService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * 外部接口调用
 *
 * @author syw
 * @since 2023-06-29
 **/
@RestController
@RequestMapping(value = "/monitor")
@Api(tags = "监控接口")
@RequiredArgsConstructor
public class MonitorController extends BaseController {

    private final IMonitorService monitorService;


    @ApiOperation(value = "查询监控列表信息")
    @PostMapping("/list")
    public Response<List<MonitorRecordVO>> getMonitorList(@Validated @RequestBody MonitorRecordQueryVO data) {
        Long accountId = getLoginAccount().getAccountId();
        return ResponseFactory.okResponse(monitorService.getMonitorList(accountId, data));
    }

    @ApiOperation(value = "添加监控信息")
    @PostMapping("/add")
    public Response<Long> addMonitor(@Validated @RequestBody MonitorRecordAddVO data) {
        Long userId = getLoginAccount().getAccountId();
        return ResponseFactory.okResponse(monitorService.addMonitor(data, userId));
    }

    @ApiOperation(value = "删除监控信息")
    @GetMapping("/remove")
    public Response<Boolean> removeMonitor(@RequestParam Long monitorId) {
        return ResponseFactory.okResponse(monitorService.removeMonitor(monitorId));
    }


    @ApiOperation(value = "添加监控信息文件")
    @PostMapping("/file/add")
    public Response<Boolean> monitorFileAdd(@Validated @RequestBody MonitorFileAddVO monitorFileAdd) {
        Long monitorRecordId = monitorFileAdd.getMonitorRecordId();
        String fileUrl = monitorFileAdd.getFileUrl();
        return ResponseFactory.okResponse(monitorService.monitorFileAdd(monitorRecordId, fileUrl));
    }


    @ApiOperation(value = "查询监控个人/企业有关案件信息")
    @GetMapping("/case/detail")
    public Response<MonitorCaseDTO> monitorCaseDetail(@RequestParam String monitorSign) {
        return ResponseFactory.okResponse(monitorService.monitorCaseDetail(monitorSign));
    }

    @ApiOperation(value = "定时查询测试")
    @GetMapping("/time/query")
    public void monitorTimeQuery() {
         monitorService.monitorTimeQuery();
    }

       @ApiOperation(value = "定时查询结果测试")
    @GetMapping("/time/query/result")
    public void monitorTimeQueryResult() {
         monitorService.monitorTimeQueryResult();
    }

}
